package ru.ifmo;

import org.hibernate.Session;
import ru.ifmo.auth.LoginUtils;
import ru.ifmo.entities.UsersEntity;

public class LoginBean {
    public UsersEntity getAuthUser() {
        return authUser;
    }

    UsersEntity authUser;

    private String login;
    private String password;
    private boolean authenticated;

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public boolean isAuthenticated() {
        return authenticated;
    }

    public void setAuthenticated(boolean authenticated) {
        this.authenticated = authenticated;
    }

    public String doLogin() {
        this.authUser = LoginUtils.getInstance().getAuthUser(login, password);
        if (authUser == null) {
            return "fail";
        } else {
            authenticated = true;
            return "success";
        }
    }

    public String doLogout() {
        authenticated = false;
        return "success";
    }
}
